package by.grsu.as.page;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import by.grsu.as.dao.DaoZayava;
import by.grsu.as.model.Zayava;

@SuppressWarnings("serial")
public class ListZayavasPage extends BasePage {

	@SpringBean
	private DaoZayava zayavaDao;

	public ListZayavasPage() {
		super();

		final List<Zayava> zayavas = zayavaDao.findAll();

		add(new ListView<Zayava>("list", zayavas) {
			@Override
			protected void populateItem(final ListItem<Zayava> item) {
				final Zayava zayava = item.getModelObject();
				item.add(new Label("client", zayava.getClient().getLastname()));
				item.add(new Label("admin", zayava.getAdmin().getLastname()));
				item.add(new Label("car", zayava.getCar().getName()));
				item.add(new Label("rentalDays", String.valueOf(zayava
						.getClient().getDays())));
				Double cost = zayava.getCar().getKoeff()
						* zayava.getClient().getDays();
				item.add(new Label("cost", String.valueOf(cost)));
				/*
				 * item.add(new Link<Zayava>("editLink",new
				 * Model<Zayava>(zayava)){
				 * 
				 * @Override public void onClick(){ setResponsePage(new
				 * EditZayava(zayava)); } });
				 */
			}
		});
		/*
		 * add(new Link<Zayava>("createLink", new Model<Zayava>(new Zayava())) {
		 * 
		 * @Override public void onClick() { setResponsePage(new
		 * EditZayava(getModelObject())); } });
		 */
	}

}
